<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
    <script src="js/browser.min.js"></script>
    <script></script>
</head>
<body>
    <div id='example'></div>

    <script type="text/babel">
    /*
                    {
                       this.state.isShow
                       &&
                       <h1>Hello React</h1>
                    }
    */
        // 点击按钮，决定h1显示或者移除
        var TestComponent = React.createClass({
            getInitialState:function(){
                return {
                    isShow:true
                }
            },
            handleClick:function(){
             //将状态的值 每次设置和 之前相反的值
             var now = this.state.isShow;
             this.setState({isShow:!now});
            },
            showInfo:function(){
                //在该方法中 会根据表达式执行的结果 真假 来决定是否要返回h1标签
                if(this.state.isShow){
                    return <h1>Hello React</h1>
                }
            },
            render:function(){
                return <div>
                    {
                        this.showInfo()
                    }
                    <button onClick={this.handleClick}>
                        clickMe
                    </button>
                </div>
            }
        });

        ReactDOM.render(
            <TestComponent></TestComponent>,
            document.getElementById('example')
        );
    </script>
</body>
</html>